package nancal.mp.client.integration

import nancal.mp.model.DepItem
import nbcp.base.comm.ApiResult
import org.springframework.cloud.openfeign.FallbackFactory
import org.springframework.cloud.openfeign.FeignClient
import org.springframework.stereotype.Component
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping

@FeignClient("mp-integration", fallbackFactory = TestFall::class)
interface TestFeignClient {

    @RequestMapping("/hi")
    fun hi(): String

    @GetMapping("/dependency-services")
    fun dep(): ApiResult<DepItem>
}


@Component
class TestFall : FallbackFactory<TestFeignClient> {
    override fun create(cause: Throwable?): TestFeignClient {
        return  object: TestFeignClient {
            override fun hi(): String {
                return "OK";
            }

            override fun dep(): ApiResult<DepItem> {
                return ApiResult.error("no")
            }
        }
    }

}